package fr.utbm.gi.vi51.project.environment;

import java.util.ArrayList;

import javax.vecmath.Point2d;

import fr.utbm.gi.vi51.framework.FrameworkLauncher;
import fr.utbm.gi.vi51.framework.environment.Animat;
import fr.utbm.gi.vi51.project.agent.Enemy;

public class Map {

	protected ArrayList<Object> mapObject;
	protected ArrayList<Point2d> positionList;
	protected ArrayList<Point2d> wayPointList;
	protected ArrayList<Point2d> spawnSpot;
	protected String name;

	public Map() {
		this.mapObject = new ArrayList<>();
		this.positionList = new ArrayList<>();
		this.wayPointList = new ArrayList<>();
		this.spawnSpot = new ArrayList<>();
	}

	public Map(String _name) {
		this.name = _name;
		this.mapObject = new ArrayList<>();
		this.positionList = new ArrayList<>();
		this.wayPointList = new ArrayList<>();
		this.spawnSpot = new ArrayList<>();
	}

	public void add(Object obj) {
		this.mapObject.add(obj);
	}

	public String getName() {
		return this.name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public Object getMapObject(int index) {
		return this.mapObject.get(index);
	}

	public void addCoord(Point2d p) {
		this.positionList.add(p);
	}

	public void addWayPoint(Point2d p) {
		this.wayPointList.add(p);
	}

	public ArrayList<Point2d> getWayPointList() {
		return this.wayPointList;
	}

	public void addSpawnSpot(Point2d p) {
		this.spawnSpot.add(p);
	}

	public Point2d getSpawnSpot(int index) {
		try {
			return (this.spawnSpot.get(index));
		} catch (Exception e) {
			return (new Point2d(1000, 350));
		}
	}

	public void launch() {
		int i = 0;
		for (int j = 0; j < this.mapObject.size(); ++j) {
			Object obj = this.mapObject.get(j);
			if (obj instanceof EnvironmentObject) {
				FrameworkLauncher.launchEnvironmentObject((EnvironmentObject) obj);
			} else if (obj instanceof Enemy) {
				FrameworkLauncher.launchAgent((Animat<?>) obj, this.positionList.get(i).getX(), this.positionList
						.get(i).getY());
				++i;
			}

		}

	}

}
